package com.assess.web.controller;


import com.assess.web.model.Address;
import com.assess.web.model.Company;
import com.assess.web.service.AddressService;
import com.assess.web.service.CompanyService;

import com.assess.web.util.RespParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 抽选设置
 */
@Controller
@RequestMapping("/selection")
public class SelectionController extends BaseController {

    @Autowired
    private CompanyService companyService;
    @Autowired
    private AddressService addressService;

    /**
     * 跳转抽选设置 页面
     *
     * @return
     */
    @RequestMapping("set")
    public ModelAndView selection() {
        ModelAndView view = new ModelAndView("/selection/set");
        view.addObject("companyList", companyService.listCompany());
        return view;
    }

    /**
     * 获取所有的企业
     *
     * @return
     */
    @ResponseBody
    @PostMapping("company/list")
    public RespParam<List<Company>> ListCompany() {
        return success(companyService.listCompany());
    }

    /**
     * 获取企业下的标段地址
     *
     * @param companyId
     * @return
     */
    @ResponseBody
    @PostMapping("address/list")
    public RespParam<List<Address>> ListAddress(@RequestParam("companyId") Integer companyId) {
        return success(addressService.listAddress(companyId));
    }


}
